package com.ivr.cm.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.ivr.cm.dao.ILimitUserNumDao;
import com.ivr.cm.vo.LimitUserNumVo;
/**
 * 用户当日拨打次数限制数据实现层
 * @author liugeng
 *
 */
public class LimitUserNumDaoImpl extends JdbcDaoSupport implements ILimitUserNumDao {
	private static Logger logger = Logger.getLogger(LimitUserNumDaoImpl.class);
	
	/**查询出用户当日拨打次数限制信息*/
	@SuppressWarnings("unchecked")
	@Override
	public LimitUserNumVo getLimitUserNumList() {
		String sql = "select day_num from tb_ivr_limit_user_num where status = 1";
		logger.info(String.format("查询出用户当日拨打次数限制信息[%s]", sql));
		
		List<LimitUserNumVo> limitUserNumVoList = this.getJdbcTemplate().query(sql, rowMapper);
		if(limitUserNumVoList != null && limitUserNumVoList.size() > 0){
			return limitUserNumVoList.get(0);
		}
		return null;
	}
	
	private ParameterizedRowMapper<LimitUserNumVo> rowMapper = new ParameterizedRowMapper<LimitUserNumVo>() {
		@Override
		public LimitUserNumVo mapRow(ResultSet rs, int rowNum) throws SQLException {
			LimitUserNumVo limitUserNumVo = new LimitUserNumVo();
			limitUserNumVo.setDay_num(rs.getInt("day_num"));
			return limitUserNumVo;
		}
	};

}
